package com.chinamsp.codegen.convert.db;

import javax.validation.constraints.Pattern;
import javax.validation.constraints.Pattern.Flag;

import org.hibernate.validator.constraints.NotBlank;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.validation.annotation.Validated;

import com.chinamsp.codegen.CodeGenConstants;
import com.chinamsp.dydb.DydbContstants;

/**
 * db 配置
 * @author shifenghu
 *
 */
@ConfigurationProperties(prefix =  CodeGenConstants.PROPERTIES_PREFIX)
@Validated
public class DbCodeGenProperties {

	/**
	 * 包名
	 */
	@NotBlank
	private String packageName;
	
	
	/**
	 * 例外的表
	 */
	private String exclusions;
	
	/**
	 * 包含的表，如果 exclusions 和  includes 都存在，则只取 include
	 */
	private String includes;
	
	/**
	 * 要处理 的 schema
	 */
	@NotBlank
	private String schema;
	

	/**
	 * 处理区分大小写
	 */
	@Value("${" + DydbContstants.PROPERTIES_PREFIX +  ".url}")
	@Pattern(regexp = INFROMATION_NAME, flags = Flag.CASE_INSENSITIVE, message = "数据库 uri 必须配置访问 information_schema 库")
	private String dbUrl;

	public String getPackageName() {
		return packageName;
	}

	public void setPackageName(String packageName) {
		this.packageName = packageName;
	}

	public String getExclusions() {
		return exclusions;
	}

	public void setExclusions(String exclusions) {
		this.exclusions = exclusions;
	}

	public String getIncludes() {
		return includes;
	}

	public void setIncludes(String includes) {
		this.includes = includes;
	}

	public String getSchema() {
		return schema;
	}

	public void setSchema(String schema) {
		this.schema = schema;
	}
	
	
	private static final String INFROMATION_NAME = ".*information\\_schema.*";
	
}
